<template>
  <div>
    <div class="header">开发管理页面</div>

    <div class="header_item">
      <p>
        搜索:
        <el-input v-model="key" placeholder="请输入内容"></el-input>
      </p>
      <p>
        <el-select v-model="value" clearable placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </p>
    </div>
    <!-- --------------------------列表------------------------------------- -->
    <div class="bugListBox">
      <template>
        <el-table :data="bugList" border style="width: 100%">
          <el-table-column fixed prop="start" label="日期" width="180">
            <template slot-scope="scope">
              {{ dateFormate(scope.row.start, "yyyy年mm月dd日 hh:mm:ss") }}
              <!-- 这个方法dateFormate写在了main.js中 利用构造函数原型继承的原理 -->
            </template>
          </el-table-column>
          <el-table-column prop="username" label="测试人员姓名" width="120"></el-table-column>

          <el-table-column prop="usertype" label="项目组" width="70"></el-table-column>
          <el-table-column prop="bugreason" label="BUG详情" width="350"></el-table-column>
          <el-table-column prop="zip" label="附件" width="120">
            <template slot-scope="scope" v-if="scope.row.imgurl">
              <!-- <img  v-for="(item,index) in scope.row.extend.split('_')" :key="index" :src="item"> -->
              <el-image
                style="width: 100px; height: 60px"
                :src="scope.row.imgurl.split('|')[0]"
                :preview-src-list="scope.row.imgurl.split('|')"
              ></el-image>
            </template>
          </el-table-column>
          <el-table-column label="状态" width="120">
            <!-- -------------------------状态------------------------------ -->
            <template slot-scope="scope">
              <el-button type="danger" v-if="scope.row.type == 1">待修复</el-button>
              <el-button type="warning" v-if="scope.row.type == 2">待测试</el-button>
              <el-button type="success" v-if="scope.row.type == 3">已完成</el-button>
            </template>
          </el-table-column>
          <!-- -------------------------------------操作----------------------------- -->
          <el-table-column fixed="right" label="操作" width="200">
            <template slot-scope="scope">
              <!-- <el-button
                type="danger"
                v-if="scope.row.type == 1"
                @click="updateType(scope.row, 2)"
                >提交开发</el-button
              >-->
              <span v-if="scope.row.type == 1">
                <el-button type="success" @click="updateType(scope.row, 2)">已修复提交测试</el-button>
                <!-- <el-button type="success" @click="updateType(scope.row,3)"
                  >修复完成</el-button
                >-->
              </span>
              <!-- <el-button
                type="success"
                v-if="scope.row.type == 3"
                @click="removeBug(scope.row)"
                >修复完成删除</el-button
              >-->
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="pagesize"
      @current-change="change"
    ></el-pagination>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
export default {
  data() {
    return {
      input: "",
      // total:100,
      // pagrsize:3,
      type: 2,
      pagesize: 5, //每页显示的数据
      page: 1, //第几页
      key: "",
      options: [
        {
          value: 1,
          label: "待修复"
        },
        {
          value: 2,
          label: "待测试"
        },
        {
          value: 3,
          label: "已完成"
        }
      ],
      value: "",
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        }
      ]
    };
  },
  computed: {
    ...mapState("programInfo", ["bugList", "total"])
  },
  watch: {
    key() {
      this.page = 1; //查询条件发生改变以后 都是请求第一页
      this.all();
    },
    type() {
      this.page = 1;
      this.all();
    },
    value() {
      this.page = 1;
      console.log(this.value);
      this.all();
    }
  },
  methods: {
    ...mapActions("programInfo", ["getBugList", "updateBug"]),
    handleClick(row) {
      console.log(row);
    },
    change(page) {
      this.page = page * 1;
      this.all();
    },
    all() {
      this.getBugList({
        page: this.page,
        shownum: this.pagesize,
        key: this.key,
        type: this.value
      });
    },
    updateType(item, type) {
      console.log(item, type);
      item.type = type;
      this.updateBug({ _id: item._id, type });
    }
  },

  created() {
    this.all();
  }
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}
.header {
  width: 1200px;
  margin: 0 auto;
  font-size: 18px;
  font-weight: 700;
  padding: 20px 0;
}
.header_item {
  width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
}
.header_item p {
  text-align: left;
  text-indent: 10px;
  width: 200px;
  margin-bottom: 20px;
  font-size: 18px;
  font-weight: 600;
  padding: 5px;
}
.bugListBox {
  width: 1200px;
  margin: 0 auto;
}
</style>
